package com.company;

import java.io.*;
import java.net.Socket;

public class Clients {

    private String name;
    public Clients(String name){this.name = name;}
    public void test(String p){
        System.out.println(this.name + " Test" + p );
    }

    public static void main(String[] args) throws Exception {
        int i = 1;
        new Main.WnetWScreenRecordPlayer();
        while (true) {
            Thread.sleep(40);
            //1.创建 Socket 对象
            Socket s = new Socket("127.0.0.1", 9999);

            //2.从连接中取出输出流并发消息
            OutputStream os = s.getOutputStream();
            os.write(i);

            //3.从连接中取出输入流并接收回话
            InputStream is = s.getInputStream(); //阻塞
            BufferedInputStream bis = new BufferedInputStream(is);
            byte[] b = new byte[4096];
            int len = -1;
            FileOutputStream fos = new FileOutputStream(new File(System.getProperty("user.dir") + "/recodes/" + i++ + ".jpg"));
            while ((len = bis.read(b)) != -1) {
                fos.write(b,0,len);
            }
            //4.关闭
            fos.close();
            s.close();

        }
    }
}
